//
//  NewsClass.m
//  LCKJDS
//
//  Created by 胡品 on 16/5/23.
//  Copyright © 2016年 LCKJ. All rights reserved.
//

#import "NewsClass.h"

@implementation NewsClass

-(NewsClass*)init
{
    self=[super init];
    if (self) {
    lastbutton =[[NSMutableArray alloc]init];
        
        self.showsHorizontalScrollIndicator=NO;
        self.showsVerticalScrollIndicator=NO;
        self.pagingEnabled=YES;
    }
    return self;

}

//实现frameiamge
-(void)sortButtonSV:(UIButton*)button
{
    
    NSInteger w;
    UIButton * lastobjstButton = [lastbutton lastObject];
    if (lastobjstButton) {
        
        //两个button之间有10的距离
        w = lastobjstButton.frame.origin.x + lastobjstButton.frame.size.width+20;
        
    }else{
        
        w = 0;
        
    }
    
    [lastbutton addObject:button];
    [self addSubview:button];
    
    CGRect frame = button.frame;
    
    frame.origin.x=w;
    frame.origin.y =0;
    
    button.frame = frame;
    
    //滑动间距
    self.contentSize = CGSizeMake(w + button.frame.size.width, 0);
    
    if (w > [UIScreen mainScreen].bounds.size.width) {
        
        self.contentSize = CGSizeMake(w + button.frame.size.width, 0);
    }
}


-(void)buttonTitles:(NSArray *)array
{
    for (int i = 0; i < array.count; i++) {
        UIButton * but = [[UIButton alloc]init];
        
        but.frame=CGRectMake(0, 0, 61, 30);
        
        //字体加粗
        but.titleLabel.font = [UIFont boldSystemFontOfSize:20];
        
        but.layer.cornerRadius = 10;
        
        [but setTitle:array[i] forState:UIControlStateNormal];
        
        [but setTitleColor:[UIColor colorWithRed:0.0/255.0 green:0.0/255.0 blue:255.0/255.0 alpha:1] forState:UIControlStateNormal];
        
        
        but.tag = i;
        
        [but addTarget:self action:@selector(butt:) forControlEvents:UIControlEventTouchUpInside];
        
        
        [self sortButtonSV:but];
    }
}

//点击事件
-(void)butt:(UIButton *)sender
{
    
    [self.delegata PassValuesButtonTag:sender.tag];
    [self clearColorer];
    
    sender.backgroundColor = [UIColor colorWithRed:207.0/255.0 green:207.0/255.0 blue:207.0/255.0 alpha:0.5];
    
    
}

-(void)clearColorer
{
    for (UIButton * but in lastbutton) {
        
        but.backgroundColor = [UIColor clearColor];
        
    }
        
}


@end
